#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
****************************************************
Project:python
Filename: ymacat.py
Author:银河
Create: 2025/10/13 上午11:16 
Notes:源码猫，主页：https://www.ymcat.cn/    账号：sa_js  sa_sh   密码：asdf1234
cron: 22 2 * * *
***************************************************
'''

import time
import requests

class CheckIn(object):
    def __init__(self):
        self.headers = {
                "accept": "application/json, text/javascript, */*; q=0.01",
                "accept-language": "zh-CN,zh;q=0.9",
                "cache-control": "no-cache",
                "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
                "origin": "https://www.ymcat.cn",
                "pragma": "no-cache",
                "priority": "u=1, i",
                "referer": "https://www.ymcat.cn/",
                "sec-ch-ua": "'Google Chrome';v='141', 'Not?A_Brand';v='8', 'Chromium';v='141'",
                "sec-ch-ua-mobile": "?0",
                "sec-ch-ua-platform": "'Windows'",
                "sec-fetch-dest": "empty",
                "sec-fetch-mode": "cors",
                "sec-fetch-site": "same-origin",
                "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36",
                "x-requested-with": "XMLHttpRequest"
            }
        self.users = [
                {"username": "sa_js", "password": "asdf1234"},
                {"username": "sa_sh", "password": "asdf1234"}
            ]
        self.content = ''


    def check(self,session,user):
        try:
            data = {
                "action": "user_checkin"
            }
            res = session.post(url="https://www.ymcat.cn/wp-admin/admin-ajax.php",data=data,headers=self.headers).json()
            print(res)
            self.content += f'''
                    <div>签到账号：{user['username']}</div>
                    <div>签到内容：{res['msg']}</div>
                    <hr>
            '''
        except Exception as e:
            self.weixin(f"源码猫签到异常，{e}")

    def login(self,username,password):
        try:
            session = requests.session()
            data = {
                "username": username,
                "password": password,
                "remember": "forever",
                "action": "user_signin",
            }
            session.post(url="https://www.ymcat.cn/wp-admin/admin-ajax.php",data=data,headers=self.headers).json()
            return session
        except Exception as e:
            self.weixin(f"源码猫登录异常,{e}")
    def weixin(self,content):
        data = {
            "title": "源码猫签到提醒",
            "content": content
        }
        res = requests.post(url="http://yh.xuenn.cn/api/weixin/", data=data)
        if res.status_code == 200:
            print('pushplus推送成功')
            return 'pushplus推送成功'
        else:
            print('系统错误，pushplus推送失败')
            return '系统错误，pushplus推送失败了'

    def main(self):
        for user in self.users:
            print(user)
            session = self.login(user['username'], user['password'])
            self.check(session,user)
            time.sleep(5)
        self.weixin(self.content)

if __name__ == '__main__':
    CheckIn().main()

